import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router);
//按需加载,当渲染其他页面时才加载其组件,并缓存,减少首屏加载时间
const Index = resolve => require(['@/views/Index.vue'], resolve)
const Category = resolve => require(['@/views/Category.vue'], resolve)
const CategoryMain = resolve => require(['@/components/category/main.vue'], resolve)
const Car = resolve => require(['@/views/Car.vue'], resolve)
const User = resolve => require(['@/views/User.vue'], resolve)
const Detail = resolve => require(['@/views/Detail.vue'], resolve)
const Search = resolve => require(['@/views/Search.vue'], resolve)
const Pay = resolve => require(['@/components/car/pay/pay.vue'], resolve)
const userLogin = resolve => require(['@/views/userLogin.vue'], resolve)
const order = resolve => require(['@/views/order.vue'], resolve)
const setUp = resolve => require(['@/views/setUp.vue'], resolve)
const changePhone = resolve => require(['@/views/changePhone.vue'], resolve)
const means = resolve => require(['@/views/means.vue'], resolve)
const team = resolve => require(['@/views/team.vue'], resolve)
const notice = resolve => require(['@/views/notice.vue'], resolve)
const mission = resolve => require(['@/views/mission.vue'], resolve)
const business = resolve => require(['@/views/business.vue'], resolve)
const attestation = resolve => require(['@/views/attestation.vue'], resolve)
const address = resolve => require(['@/views/address.vue'], resolve)
const addAddress = resolve => require(['@/views/addAddress.vue'], resolve)
const updateAddress = resolve => require(['@/views/updateAddress.vue'], resolve)
const land = resolve => require(['@/views/land.vue'], resolve)
const QR = resolve => require(['@/views/QR.vue'], resolve)
const phoneLogin = resolve => require(['@/views/phoneLogin.vue'], resolve)
const paySure = resolve => require(['@/views/paySure.vue'], resolve)
const watter = resolve => require(['@/views/watter.vue'], resolve)


const router = new Router({
  mode: 'history',
  routes: [{
    path: '/',
    name: '唯硒商城',
    component: Index
  }, {
    path: '/category',
    name: '活动',
    component: Category
  }, {
    path: '/car',
    name: '购物车',
    component: Car
  }, {
    path: '/car/pay',
    name: '支付',
    component: Pay
  }, {
    path: '/user',
    name: '用户',
    component: User
  }, {
    path: '/detail',
    name: '详情',
    component: Detail
  }, {
    path: '/search',
    name: '搜索',
    component: Search
  }, {
    path: '/userLogin',
    name: '登录',
    component: userLogin
  }, {
    path: '/order',
    name: '我的订单',
    component: order
  }, {
    path: '/setUp',
    name: '设置中心',
    component: setUp
  }, {
    path: '/changePhone',
    name: '修改手机号',
    component: changePhone
  }, {
    path: '/means',
    name: '修改个人资料',
    component: means
  }, {
    path: '/team',
    name: '我的团队',
    component: team
  }, {
    path: '/notice',
    name: '公告中心',
    component: notice
  }, {
    path: '/mission',
    name: '任务中心',
    component: mission
  }, {
    path: '/business',
    name: '交易大厅',
    component: business
  }, {
    path: '/attestation',
    name: '实名认证',
    component: attestation
  }, {
    path: '/address',
    name: '地址管理',
    component: address
  }, {
    path: '/addAddress',
    name: '新增地址',
    component: addAddress
  }, {
    path: '/updateAddress',
    name: '修改地址',
    component: updateAddress
  }, {
    path: '/land',
    name: '土地管理',
    component: land
  }, {
    path: '/QR',
    name: '我的二维码',
    component: QR
  }, {
    path: '/phoneLogin',
    name: '手机号登陆',
    component: phoneLogin
  }, {
    path: '/paySure',
    name: '确认支付',
    component: paySure
  }, {
    path: '/watter',
    name: '我的收益',
    component: watter
  }]
})

router.afterEach((to, from, next) => {
  window, scrollTo(0, 0)
})

export default router
